<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\api;

use App\Common\CommonAbstract;
use App\Service\User\OrderService;


use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;

/**
 * 支付回调控制器
 *
 * @AutoController()
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\api
 */
class OrdersNotifyController extends CommonAbstract
{
    /**
     * @Inject
     * @var OrderService
     */
    private $order_service;

    // 支付宝回调
    public function alipay()
    {

        $params = $this->request->all();

        // 记录日志
        $this->logger('payment')->info(json_encode($params), [
            'alipay'
        ]);

        if( $params['type'] !== "charge.succeeded" ) {
            $this->logger('payment')->info("回调失败，请求错误");
            return $this->response->raw('success');
        }

        if( substr( $params['data']['object']['order_no'] , 0,5) != "order" ) {
            $this->logger('payment')->info("回调失败，订单失败");
            return $this->response->raw('success');
        }

        $this->order_service->pingNotify( $params['data']['object'] );

        return $this->response->raw('success');
    }
}